package Gui;

import java.awt.BorderLayout;
import java.awt.Color;

import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.accessibility.AccessibleContext;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import javax.swing.JTextArea;
import javax.swing.JTextField;

import controller.ContactEventControl;
import controller.CreateListControl;
import controller.CustomerControl;
import controller.HistoryControl;
import controller.MarketingTemplateControl;



import java.awt.SystemColor;
import javax.swing.JComboBox;
// TODO: Auto-generated Javadoc

/**
 * The Class ContactCustomer.
 */
public class ContactCustomer extends JPanel {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -6400283674228776823L;
	
	/** The Display list button. */
	public static JButton DisplayListButton;
	
	/** The back button. */
	public static JButton backButton = new JButton("Back");
	
	/** The confirmation lable. */
	public static JLabel confirmationLable=null;
	
	/** The text area. */
	public static JTextArea textArea = new JTextArea();
	
	/** The mf. */
	private mainf mf;
	
	/** The lst. */
	private static CreateListControl lst;
	
	/** The cc. */
	private static ContactEventControl cc;
	
	/** The Customertext field. */
	public static JTextField CustomertextField;
	
	/** The C history. */
	private HistoryControl CHistory;
	
	/** The Deal i dtext field. */
	public static JTextField DealIDtextField;
	
	/** The salelist. */
	public static String[] salelist;
	
	/** The username. */
	public static String username;
	
	/** The preslist. */
	public static String preslist;
	int flag=0;
;

	
	/**
	 * Instantiates a new contact customer.
	 */
	public ContactCustomer()
	{
		super();
		viewContact();
	}


	/**
	 * View contact.
	 */
	public void viewContact(){
		username=LoginForm.UserNameTextField.getText();
		this.setSize( 1500,765 ); //set Frame size
		this.setLayout(null); //set layout
		this.setBackground(SystemColor.activeCaption); // set Background color to blue
		cc.asklist();
	
		JLabel inquiriesLabel = new JLabel("To check customer's Inquiries History please insert the following details:");
		inquiriesLabel.setFont(new Font("Arial", Font.PLAIN, 14));
		inquiriesLabel.setBounds(88, 78, 469, 31);
		add(inquiriesLabel);
		
		JLabel DealIDLabel = new JLabel("Deal ID:");
		DealIDLabel.setBounds(128, 186, 95, 14);
		add(DealIDLabel);
		
		JLabel CustomerIDLabel = new JLabel("Customer ID:");
		CustomerIDLabel.setBounds(128, 135, 89, 14);
		add(CustomerIDLabel);
	
		DealIDtextField = new JTextField();
		DealIDtextField.setBounds(221, 183, 137, 20);
		add(DealIDtextField);
		DealIDtextField.setColumns(10);
		
		CustomertextField = new JTextField();
		CustomertextField.setBounds(221, 132, 137, 20);
		add(CustomertextField);
		CustomertextField.setColumns(10);
		
		backButton.setBounds(354, 232, 89, 23);
		add(backButton);
	
		
		JButton CheckButton = new JButton("Check");
		CheckButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CHistory=new HistoryControl();
				if(CustomertextField.getText().isEmpty() || DealIDtextField.getText().isEmpty())
				{
					confirmationLable.setVisible(true);
					 confirmationLable.setText("Please fill all the fields!!");
				}
				 else{ 
					
							for(int j=0;j<lst.list.length-1;j++){
								if(lst.list[j].contains(CustomertextField.getText())){
									CHistory.CheckHistory(CustomertextField.getText(),DealIDtextField.getText());
									confirmationLable.setVisible(true);
									flag=1;
								}
								else{
									confirmationLable.setVisible(true);
							 		confirmationLable.setText("Customer not in the list!!");
								}
							
							}	
				 }

			}
	//***		
		});
		CheckButton.setBounds(221, 232, 89, 23);
		add(CheckButton);
		
		confirmationLable = new JLabel("");           // set result label
		confirmationLable.setBounds(221, 282, 215, 31);
		add(confirmationLable);                        // add label to the panel
		confirmationLable.setVisible(false); 
	
	
	lst=new CreateListControl();
	JButton btnPresentList = new JButton("Present list");
	btnPresentList.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			String listm=mf.lista;
			salelist=lst.dividelist(listm,username);
			textArea.setText(preslist);
			textArea.setVisible(true);
		}
	});
	btnPresentList.setBounds(724, 78, 148, 23);
	add(btnPresentList);
	
	textArea.setEditable(false);
	textArea.setBounds(686, 112, 441, 292);
	add(textArea);
	
	
	}
}